
global bin=10
global bin_name=10
global data_in=20
global data_out=1180
global range             "RC>=float(${data_in}) & RC<=float(${data_out})"
global cutoff=300
global zoom_in_c300     =80     
global zoom_out_c300    =470
global range_c300      "incbin${binname}>=float(${zoom_in_c300}) & incbin${binname}<=float(${zoom_out_c300})"


use "${processed_data}\trading_rights_asif.dta" , clear 
****
_pctile  tfpq,  p(1 99)
drop if tfpq<=r(r1) | tfpq>=r(r2) 
***

keep  if  ${firm}==1 & ${condition}  & ${range} 
gen tinctobin= RC/${bin}  //registered capital; unit 10K RMB
gen incbinaux=floor(tinctobin)
gen incbin${binname}=incbinaux*${bin}
drop  tinctobin   incbinaux
keep if ${range_c300}

keep if year==2000 | year==2002 
gen Post=.
replace Post=1 if year==2002
replace Post=0 if year==2000 

***balanced panel     //what is firm id?   this needs to be changed!
bysort id: gen dup=_N
tab dup
drop if dup==1 
drop dup 


xtset id year
gen incbin${binname}_L2=L2.incbin${binname}
gen incbin${binname}_F2=F2.incbin${binname}
gen RC_L2=L2.RC 

keep year Post id fid cic_adj2  trade_custom*  tfpq*  RC RC_L2 incbin${binname}*



********************RC_2000>=300
ivregress 2sls tfpq i.cic_adj2  (trade_custom=Post) if (year==2000 & incbin${binname}>=${cutoff}  )  | (year==2002 & incbin${binname}_L2>=${cutoff} )  

reg trade_custom Post i.cic_adj2 if (year==2000 & incbin${binname}>=${cutoff} )  | (year==2002 & incbin${binname}_L2>=${cutoff}) , vce(bootstrap, rep(300))  

reg tfpq Post i.cic_adj2 if (year==2000 & incbin${binname}>=${cutoff} )  | (year==2002 & incbin${binname}_L2>=${cutoff})  , vce(bootstrap, rep(300)) 



